package
{
	import org.flixel.*;
	
	public class PlumeSource extends FlxSprite
	{
		protected var m_isOn:Boolean;
		protected var m_forge:SourceForge;
		protected var m_beam:SourceBeam;
		protected var m_element:int;
		private var lightOn:Boolean;
		protected var lightingAnimator:FlxSprite;
		
		public function PlumeSource(_x:int, _y:int, lA:FlxSprite, _img:Class=null) {
			super(_x, _y, _img);
			
			lightingAnimator = lA;
			lightingAnimator.addAnimation("silent", [0], 1);
			lightingAnimator.addAnimation("lightOn", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], 16);
			lightingAnimator.addAnimationCallback(stopLightingAnim);
			
			lightOn = false;
		}
		
		// Returns true is source is currently emitting a beam.
		public function set on(b:Boolean):void {
			m_isOn = b;
		}
		
		// Returns true is source is currently emitting a beam.
		public function get on():Boolean {
			return m_isOn;
		}
		
		public function setBeam(beam:SourceBeam, forge:SourceForge):void {
			m_beam = beam;
			m_forge = forge;
			m_isOn = true;
		}
		
		public function removeBeam():void {
			if (m_forge != null) {
				m_forge.removeSource(m_element);
			}
			m_forge = null;
			m_beam = null;
			m_isOn = false;
		}
		
		// Get the element type of the plume source (e.g. earth, wind, etc.)
		public function get element():int {
			return m_element;
		}
		
		public override function update():void {
			super.update();
		}
		
		public function get beam():SourceBeam {
			return m_beam;
		}
		
		public function turnOn():void {
			lightOn = true;
		}
		
		public function turnOff():void {
			lightOn = false;
		}
		
		public function isLightOn():Boolean {
			return lightOn;
		}
		
		private function stopLightingAnim(name:String, frameNumber:int, frameIndex:int):void {
			if (lightingAnimator.finished) {
				lightingAnimator.loadGraphic(Res.blankImage, false, false, 1,1, false);
				lightingAnimator.play("silent");
			}
		}
	}
}